package yja.gzw.app.adapter

import android.content.Context
import android.content.Intent
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CircleCrop
import com.bumptech.glide.request.RequestOptions
import yja.gzw.app.R
import com.tencent.imsdk.v2.V2TIMConversation
import com.tencent.qcloud.tuicore.TUIConstants
import com.tencent.qcloud.tuikit.tuichat.classicui.page.TUIC2CChatActivity

class Haoyouadapter (private val context: Context, private val list: List<V2TIMConversation>): RecyclerView.Adapter<RecyclerView.ViewHolder>(){
    private var view: View?=null

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        view= LayoutInflater.from(parent.context).inflate(R.layout.item_view_haoyou,parent,false)
        Log.e("图片地址展示","走到了2")
        return ViewHodeView(view!!)
    }

    override fun getItemCount(): Int {
       return list.size
    }



    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        if(holder is ViewHodeView){
            holder.haoyouname.text=list[position].showName

            //todo 报错空指针  暂且不知道是给那个值赋值
           // holder.neirun.text= " "+list[position].lastMessage.textElem.text.toString()
            val requestOptions = RequestOptions.bitmapTransform(CircleCrop())
            if(list[position].lastMessage.faceUrl==""){
                Glide.with(context).load(R.mipmap.touxiang)
                    .apply(requestOptions)
                    .into(holder.touxiang)
            }else{

                Glide.with(context).load(list[position].lastMessage.faceUrl)
                    .apply(requestOptions)
                    .into(holder.touxiang)
            }




            Log.e("个人的详细", list[position].userID+" 1"+
                    list[position].faceUrl+" 2"+
                    list[position].groupID+" 3"+
                    list[position].conversationID+" 4"+
                    list[position].customData+" 5"+
                    list[position].draftText+" 6"+
                    list[position].groupType+" 7"+
                    list[position].c2CReadTimestamp+" 8"+
                    list[position].conversationGroupList+" 9"+
                    list[position].draftTimestamp+" 10"+
                    list[position].groupAtInfoList+" 11"+
                    list[position].groupReadSequence+" 12"+
                    list[position].isPinned+" 13"+
                    list[position].lastMessage+" 14"+
                    list[position].markList+" 15"+
                    list[position].unreadCount

            )
            holder.itemView.setOnClickListener {




                val intent = Intent(context, TUIC2CChatActivity::class.java)
                intent.putExtra(TUIConstants.TUIChat.CHAT_ID,list[position].userID);
                intent.putExtra(TUIConstants.TUIChat.CHAT_TYPE, V2TIMConversation.V2TIM_C2C)
               context.startActivity(intent)

            }

        }



    }

    inner class ViewHodeView(itemView: View):RecyclerView.ViewHolder(itemView){
        val haoyouname: TextView =itemView.findViewById(R.id.haoyouname)
        val touxiang: ImageView =itemView.findViewById(R.id.touxiang)
        val neirun: TextView =itemView.findViewById(R.id.neirun)

    }


}